<template>
    <div class="col-md-4">
      <form class="form-horizontal">
        <div class="form-group">
          <label>用户名</label>
          <input type="text" class="form-control" placeholder="用户名" v-model.trim="user">
        </div>
        <div class="form-group">
          <label>评论内容</label>
          <textarea class="form-control" rows="6" placeholder="评论内容" v-model.trim="content"></textarea>
        </div>
        <div class="form-group">
          <div class="col-sm-offset-2 col-sm-10">
            <button type="button" class="btn btn-default pull-right" @click="add">提交</button>
          </div>
        </div>
      </form>
    </div>
</template>

<script>
export default {
  data(){
    return{
      user:'',
      content:''
    }
  },
  props:{
    addComment: {
       type:Function,
       required:true
    }
  },
  name: "commentAdd",
  methods:{
     add(){
       const user = this.user;
       let content = this.content;
       if(!user || !content){
         alert('用户名或者内容为空')
         return
       }

       let commmet={user,content};
       this.addComment(commmet);
       //清除输入
       this.user=''
       this.content=''

     }
  }
}

</script>

<style scoped>

</style>
